package easymall.service;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import easymall.dao.CartDao;
import easymall.po.Cart;
import easymall.pojo.MyCart;
@Service("cartService")
public class CartServiceImpl implements CartService {
	@Autowired
	private CartDao cartDao;
	
	@Autowired
	private MongoTemplate mongoTemplate;
	
	@Override
	public Cart findCart(Cart cart) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		Query query = new Query();
		query.addCriteria(Criteria.where("user_id").is(cart.getUser_id()).and("pid").is(cart.getPid()));
		List<Cart> carts = mongoTemplate.find(query, Cart.class,"cart");
//		System.out.println("0000");
//		System.out.println(carts);
//		System.out.println("0000");
		return cartDao.findCart(cart);
	}

	@Override
	public void addCart(Cart cart) {
		// TODO Auto-generated method stub
		cartDao.addCart(cart);
	}

	@Override
	public void updateCart(Cart cart) {
		// TODO Auto-generated method stub
		cartDao.updateCart(cart);
	}

	@Override
	public List<MyCart> showcart(Integer user_id) {
		// TODO Auto-generated method stub
		return cartDao.showcart(user_id);
	}

	@Override
	public void updateBuyNum(Cart cart) {
		// TODO Auto-generated method stub
		cartDao.updateBuyNum(cart);
	}

	@Override
	public void delCart(Integer cartID) {
		// TODO Auto-generated method stub
		cartDao.delCart(cartID);
	}

	@Override
	public MyCart findByCartID(Integer cartID) {
		// TODO Auto-generated method stub
		return cartDao.findByCartID(cartID);
	}

}
